﻿using System;

namespace Microsoft.Popfly.GameCreator.GameEngine.Events
{
    public class MouseHoverEventChecker : IEventChecker
    {
        private BehaviorOwner m_listenOn;
        public MouseHoverEventChecker(BehaviorOwner listenOn)
        {
            m_listenOn = listenOn;

            listenOn.AddMouseHoverEnterOrLeaveListener();
        }
        #region IEventChecker Members

        private class MouseHoverKeyEventArgs 
        {
            public string key { get { return "MouseHover"; } }
            public BehaviorOwner mouseTarget { get; private set; }

            public MouseHoverKeyEventArgs(BehaviorOwner target)
            {
                mouseTarget = target;
            }
        }
        private class MouseHoverArgs : PGCEventArgs
        {
            public MouseHoverKeyEventArgs keyEventArgs { get; private set; }
            public MouseHoverArgs(BehaviorOwner target)
            {
                keyEventArgs = new MouseHoverKeyEventArgs(target);
            }
        }

        public bool FireThisFrame(double elapsedTimeInSeconds, out BehaviorOwner sender, out PGCEventArgs args)
        {
            if (m_listenOn.HasMouseEntered() == null)
            {
                sender = null;
                args = null;
                return false;
            }
            else
            {
                sender = m_listenOn;
                args = new MouseHoverArgs(m_listenOn);
                return true;
            }
        }

        public bool IsOfEventType(string eventType)
        {
            return eventType == "mouse";
        }

        #endregion
    }
}
